package com.yxy.patient.base;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.yxy.patient.R;

public class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        //注意要清除 FLAG_TRANSLUCENT_STATUS flag
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        setStatusBarColor(R.color.white);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }

    protected void setStatusBarColor(@ColorRes int color) {
        getWindow().setStatusBarColor(getResources().getColor(color));
    }

    public void toast(Throwable throwable) {
        if (throwable != null && throwable.getMessage() != null && !throwable.getMessage().isEmpty()) {
            toast(throwable.getMessage());
        }
    }

    public void dummyToast(Throwable throwable) {
        if (throwable.getMessage() != null) {
            Log.e("BaseActivity", throwable.getMessage());
        }
    }

    public void toast(String msg) {
        if (msg != null && !msg.isEmpty()) {
            Toast toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
            toast.show();
        }
    }

    public void longToast(String msg) {
        if (msg != null && !msg.isEmpty()) {
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        }
    }

    public Intent getIntent() {
        if (super.getIntent() == null) {
            return new Intent();
        } else {
            return super.getIntent();
        }
    }
}
